/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import controller.FilesController;
import domain.File;
import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;

/**
 *
 * @author Alessio
 */
public class UpdaterCellRenderer extends DefaultListCellRenderer {

    @Override
    public Component getListCellRendererComponent(JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean hasFocus) {
        JLabel label =
                (JLabel) super.getListCellRendererComponent(list,
                value,
                index,
                isSelected,
                hasFocus);
        if (value instanceof File) {
            File file = (File) value;

            if (FilesController.getInstance().getUpdatedFiles().contains(file)) {
                label.setBackground(Color.green);
            } else if (FilesController.getInstance().getDeletedFiles().contains(file)) {
                label.setBackground(Color.red);
            } else if (FilesController.getInstance().getNewFiles().contains(file)) {
                label.setBackground(Color.cyan);
            } else {
                label.setBackground(Color.white);
            }
            if(isSelected){
                label.setBackground(Color.blue);
                label.setForeground(Color.white);
            }
        }
        return (label);
    }
}
